package com.djl.hw02server.service;

import com.djl.hw02server.domain.XmlUser;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class UserService {

    HashMap<Integer, XmlUser> xmlUsers;

    {
        xmlUsers = new HashMap<>();
        xmlUsers.put(1,new XmlUser(1,"a",11));
        xmlUsers.put(2,new XmlUser(2,"a",12));
        xmlUsers.put(3,new XmlUser(3,"a",13));
        xmlUsers.put(4,new XmlUser(4,"a",14));
        xmlUsers.put(5,new XmlUser(5,"a",15));
    }

    public XmlUser queryById(int id){
        XmlUser xmlUser = xmlUsers.get(id);
        return xmlUser==null? new XmlUser():xmlUser;
    }

    public List<XmlUser> queryAll(){
        return xmlUsers.values().stream().collect(Collectors.toList());
    }

}
